<?php
/**
 * Created by PhpStorm.
 * User: shichen
 * Date: 2018/11/2
 * Time: 14:45
 */

namespace app\admin\controller;
use app\admin\model\Article as articleModel;

use app\admin\controller\Admin;
use app\admin\controller\Ueditor;
use think\Db;
use think\Request;

class Article extends Admin
{
    public function _initialize()
    {
        parent::_initialize();
        $this->article =new articleModel() ;
    }
    public function index()
    {

        $Article=new articleModel();
        $list=Db::table('article')->select();
//        var_dump($list);die;
        return view('admin@article/index', [
            'list' => $list
        ]);

    }
//确认是否发布 显示到前台
    public function roleList($id)
    {
//
        $name = Db::table('article')->Field('status')->find($id);
//        var_dump($name['status']);
        $a=$name['status']==0? 1 : 0;
//        var_dump($a);die;

        $Article=new articleModel();
//        $result = Db::table('article')->where('artid',$id)->update(['status'=>$a]);

        //修改某个字段的值
        $res=$Article->where('artid='.$id)->setField('status',$a);
//        var_dump($res);die;

        if ($res > 0)
        {
            return $this->success('发布成功', url('admin/Article/index'));
        } else {
            return $this->error('发布失败!');
        }

    }
    public function create()
    {
        $uploadimage=new uploadimage();

        return view('article/fun3');
    }

    public function save()
    {

        var_dump($_POST);die;
        if ($p['userpass'] != $p['reuserpass'])
        {
            return $this->error('确认密码有误!');
        }
        $auser= new auserModel();
        $auser->data($p);
        $auser->userpass = $auser->setPass($p['userpass']);
        $result = $auser->allowField(true)->save();

        if ($result > 0)
        {
            return $this->success('添加成功', url('admin/Auser/index'));
        } else {
            return $this->error('添加失败!');
        }


    }
}